package com.xu.controller;

import com.xu.pojo.DevUser;
import com.xu.pojo.Info;
import com.xu.service.DevUserService;
import com.xu.util.LayData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/devuser")


public class DevUserController extends BaseController {


    @Resource
    private DevUserService devUserService;
    //跳转普通登录页
    @RequestMapping("/logion")
    public String logion() {
        return "login";
    }
   //跳转管理员登录
    @RequestMapping("/doguanli")
    public String doguanli() {
        return "logion";
    }
    //跳转第一次首页
    @RequestMapping("/list")
    public  String list(){
        return "list";
    }
//登录
    @RequestMapping("/dologion")
    public String logion(DevUser devUser, HttpSession session) {


        int count = devUserService.logion(devUser);

        if (count > 0) {

            return "First";
        } else {
            return "logion";
        }
    }

    //查询Info表并分页
    @RequestMapping(value = "/infolist3")
    @ResponseBody
    public LayData getinfolist3(@RequestParam("page") Integer page,@RequestParam("limit") Integer limit){
        int count = devUserService.count();
        List<Info> list= devUserService.getinfo(page,limit);
        System.out.println(list);
        return new LayData(0,"成功",count,list);
    }

//    根据查询ID来回显当前数据
    @RequestMapping("/getinfobyid/{id}")
    @ResponseBody
    public  Info getinfobyid(@PathVariable("id")  Integer id){
        return devUserService.getinfobyid(id);

    }
    //    点击编辑后修改信息
    @RequestMapping("/change")
    @ResponseBody
  public int updatechange(Info info){
        return devUserService.updatechange(info);
    };

}